
import Item from "antd/es/list/Item";
import FetchHelper from "../helper/fetch-helper";
import { geomToWkt, isIntersects, wktToGeom } from "../helper/mapHelper";
import _ from 'lodash';
import Fetch from "ahooks/lib/useRequest/src/Fetch";

export default class JzzyApi {
    static async listByPolygon(polygon) {
        let wkt = polygon
        if (!_.isString(polygon)) {
            wkt = geomToWkt(wkt);
        }
        const resp = await FetchHelper.getJson(`/admin-api/ybyj/jzzy/countByXlAndWkt`, {
            wkt: wkt
        })
        resp.data = resp.data?.map(item => {
            return {
                name: item.jzzyxl,
                count: item.count
            }
        })
        return resp;
    }
    static async list(params) {
        try {
            const resp = await FetchHelper.getJson(`/admin-api/ybyj/jzzy/list`, {
                // zxqhbm: window.userAreaCode,
                ...params
            })
            resp.rows = resp?.rows?.map(item => {

                if (item?.xq) {
                    try {
                        const json = JSON.parse(item?.xq);
                        return {
                            ...json,
                            ...item,
                        }
                    } catch (e) {

                    }
                }
                return item;
            })
            return resp;
        } catch (err) {
            return { rows: [] }
        }
    }
    static async listId(id) {
        try {
            const resp = await FetchHelper.getJson(`/admin-api/ybyj/jzzy/${id}`)
            return resp;
        } catch (err) {
            return { rows: [] }
        }
    }
    static async listByPolygon2(wkt) {
        if (!_.isString(wkt)) {
            wkt = geomToWkt(wkt);
        }
        const resp = await FetchHelper.getJson(`/admin-api/ybyj/jzzy/countByXlAndWkt`, {
            wkt: wkt
        })
        return resp;
    }
    //减灾能力
    static async jzll(jzzyxl, polygon) {
        let wkt = polygon
        if (!_.isString(polygon)) {
            wkt = geomToWkt(wkt);
        }
        const resp = await FetchHelper.getJson(`/admin-api/ybyj/jzzy/selectJzzymcByXlAndWkt`, {
            jzzyxl: jzzyxl,
            wkt: wkt
        })
        return resp
    }
    //后台管理中减灾资源
    static async list_serch(jzzyxl) {
        const resp = await FetchHelper.getJson(`/admin-api/ybyj/jzzy/list`, {
            jzzyxl:jzzyxl
        })
        return resp
    }
    static async groupByXl(xlmc) {
        const resp = await FetchHelper.getJson(`/admin-api/ybyj/jzzy/groupByXl`, {
            xlmc: xlmc
        })
        return resp;
    }
}